f.close() |
f.write("Hello World") |
f = open("file.txt","w") |
1 | f = open("file.txt","w") |
2 | f.write("Hello World") |
3 | f.close() |
f.close() |
f = open("UserInput.txt","w") |
i = input() |
f.write(i) |
print("Enter file contents") |
1 | print("Enter file contents") |
2 | i = input() |
3 | f = open("UserInput.txt","w") |
4 | f.write(i) |
5 | f.close() |
f.write(con) |
print("Enter a file name") |
fn = input() |
print("Enter contents") |
f = open(fn + ".txt","w") |
con = input() |
f.close() |
1 | print("Enter a file name") |
2 | fn = input() |
3 | print("Enter contents") |
4 | con = input() |
5 | f = open(fn + ".txt","w") |
6 | f.write(con) |
7 | f.close() |
f = open("Tv Shows.txt","w") |
f.write("\n") |
f.close() |
shows = ["Rick and Morty","Marvel Superheroes","The Chase"] |
f.write(shows[x]) |
for x in range(len(shows)): |
f = open("Tv Shows.txt","w") |
    f.write("\n") |
f.close() |
shows = ["Rick and Morty","Marvel Superheroes","The Chase"] |
    f.write(shows[x]) |
for x in range(len(shows)): |
1 | shows = ["Rick and Morty","Marvel Superheroes","The Chase"] |
2 | f = open("Tv Shows.txt","w") |
3 | for x in range(len(shows)): |
4 |     f.write(shows[x]) |
5 |     f.write("\n") |
6 | f.close() |
f.write("\n") |
u = input() |
f.close() |
f = open("usernames.txt","a") |
p = input() |
print("Enter a username and password") |
f.write(u + "," + p) |
1 | print("Enter a username and password") |
2 | u = input() |
3 | p = input() |
4 | f = open("usernames.txt","a") |
5 | f.write(u + "," + p) |
6 | f.write("\n") |
7 | f.close() |
print("Do you want to clear the text file") |
else: |
f = open("file.txt","a") |
f.write(i) |
f = open("file.txt","w") |
if i == "yes": |
i = input() |
f.close() |
print("What do you want to write") |
f.write("\n") |
i = input() |
print("Do you want to clear the text file") |
else: |
    f = open("file.txt","a") |
f.write(i) |
    f = open("file.txt","w") |
if i == "yes": |
i = input() |
f.close() |
print("What do you want to write") |
f.write("\n") |
i = input() |
1 | print("Do you want to clear the text file") |
2 | i = input() |
3 | if i == "yes": |
4 |     f = open("file.txt","w") |
5 | else: |
6 |     f = open("file.txt","a") |
7 | print("What do you want to write") |
8 | i = input() |
9 | f.write(i) |
10 | f.write("\n") |
11 | f.close() |
f.close() |
for x in range(20): |
f.write("\n") |
f.write(str(x+1)) |
f = open("file.txt","w") |
f.close() |
for x in range(20): |
    f.write("\n") |
    f.write(str(x+1)) |
f = open("file.txt","w") |
1 | f = open("file.txt","w") |
2 | for x in range(20): |
3 |     f.write(str(x+1)) |
4 |     f.write("\n") |
5 | f.close() |
fileName = str(x + 1) |
f = open(fileName + ".txt","w") |
for x in range(20): |
f.close() |
    fileName = str(x + 1) |
    f = open(fileName + ".txt","w") |
for x in range(20): |
    f.close() |
1 | for x in range(20): |
2 |     fileName = str(x + 1) |
3 |     f = open(fileName + ".txt","w") |
4 |     f.close() |
verseTwo() |
f.write("I need you all night, come on, dance with me") |
#clear the file |
f.write("I had a premonition that we fell into a rhythm\n") |
f = open("song.txt","a") |
f.write("And I can take you for a ride\n") |
f = open("song.txt","a") |
def verseOne(): |
f.write("I got you, moonlight, you're my starlight") |
f.write("My sugarboo, I'm levitating\n") |
f.write("\n") |
chorus() |
f.close() |
f.close() |
f.close() |
blankLine() |
def blankLine(): |
f.write("If you wanna run away with me, I know a galaxy\n") |
blankLine() |
chorus() |
blankLine() |
f.close() |
def verseTwo(): |
verseOne() |
f.write("I'm levitating") |
f = open("song.txt","a") |
f.write("Where the music don't stop for life\n") |
f.write("You want me, I want you, baby\n") |
f.write("Yeah, yeah, yeah, yeah, yeah\n") |
def chorus(): |
f.write("The Milky Way, we're renegading\n") |
f = open("song.txt","w") |
verseTwo() |
    f.write("I need you all night, come on, dance with me") |
#clear the file |
    f.write("I had a premonition that we fell into a rhythm\n") |
    f = open("song.txt","a") |
    f.write("And I can take you for a ride\n") |
    f = open("song.txt","a") |
def verseOne(): |
    f.write("I got you, moonlight, you're my starlight") |
    f.write("My sugarboo, I'm levitating\n") |
    f.write("\n") |
chorus() |
    f.close() |
    f.close() |
    f.close() |
blankLine() |
def blankLine(): |
    f.write("If you wanna run away with me, I know a galaxy\n") |
blankLine() |
chorus() |
blankLine() |
    f.close() |
def verseTwo(): |
verseOne() |
    f.write("I'm levitating") |
    f = open("song.txt","a") |
    f.write("Where the music don't stop for life\n") |
    f.write("You want me, I want you, baby\n") |
    f.write("Yeah, yeah, yeah, yeah, yeah\n") |
def chorus(): |
    f.write("The Milky Way, we're renegading\n") |
    f = open("song.txt","w") |
1 | def verseOne(): |
2 |     f = open("song.txt","w") |
3 |     f.write("If you wanna run away with me, I know a galaxy\n") |
4 |     f.write("And I can take you for a ride\n") |
5 |     f.write("I had a premonition that we fell into a rhythm\n") |
6 |     f.write("Where the music don't stop for life\n") |
7 |     f.close() |
8 | |
9 | def verseTwo(): |
10 |     f = open("song.txt","a") |
11 |     f.write("I got you, moonlight, you're my starlight") |
12 |     f.write("I need you all night, come on, dance with me") |
13 |     f.write("I'm levitating") |
14 |     f.close() |
15 | |
16 | def chorus(): |
17 |     f = open("song.txt","a") |
18 |     f.write("You want me, I want you, baby\n") |
19 |     f.write("My sugarboo, I'm levitating\n") |
20 |     f.write("The Milky Way, we're renegading\n") |
21 |     f.write("Yeah, yeah, yeah, yeah, yeah\n") |
22 |     f.close() |
23 |      |
24 | def blankLine(): |
25 |     f = open("song.txt","a") |
26 |     f.write("\n") |
27 |     f.close() |
28 | |
29 | #clear the file |
30 | verseOne() |
31 | blankLine() |
32 | chorus() |
33 | blankLine() |
34 | verseTwo() |
35 | blankLine() |
36 | chorus() |
print("Enter an input, write a ! to represent a new line") |
f.write(arr[x]) |
f.write("\n") |
i = input() |
for x in range(len(arr)): |
f = open("file.txt","w") |
f.close() |
arr = i.split("!") |
print("Enter an input, write a ! to represent a new line") |
    f.write(arr[x]) |
    f.write("\n") |
i = input() |
for x in range(len(arr)): |
f = open("file.txt","w") |
f.close() |
arr = i.split("!") |
1 | print("Enter an input, write a ! to represent a new line") |
2 | i = input() |
3 | arr = i.split("!") |
4 | f = open("file.txt","w") |
5 | for x in range(len(arr)): |
6 |     f.write(arr[x]) |
7 |     f.write("\n") |
8 | f.close() |
f.write("Salary: £" + array[x][4]) |
f.write(array[x][3] + "\n") |
f.write("\n") |
for y in range(len(address)): |
for x in range(len(array)): |
[15321,"Lynne Sherwood","44 Angel Way, North Cornelly","CF33 4PB","43,000"], |
f.write("\n") |
f.write(array[x][1] + "\n") |
array = [ |
address = array[x][2].split(",") |
[42231,"Isadore Barbra","329 Bawtry Road, Wickersley","S66 2TH","24,000"]] |
f = open(str(array[x][0]) + ".txt","w") |
f.close() |
f.write(address[y].strip() + "\n") |
    f.write("Salary: £" + array[x][4]) |
    f.write(array[x][3] + "\n") |
    f.write("\n") |
    for y in range(len(address)): |
for x in range(len(array)): |
    [15321,"Lynne Sherwood","44 Angel Way, North Cornelly","CF33 4PB","43,000"], |
    f.write("\n") |
    f.write(array[x][1] + "\n") |
array = [ |
    address = array[x][2].split(",") |
    [42231,"Isadore Barbra","329 Bawtry Road, Wickersley","S66 2TH","24,000"]] |
    f = open(str(array[x][0]) + ".txt","w") |
    f.close() |
        f.write(address[y].strip() + "\n") |
1 | array = [ |
2 |     [15321,"Lynne Sherwood","44 Angel Way, North Cornelly","CF33 4PB","43,000"], |
3 |     [42231,"Isadore Barbra","329 Bawtry Road, Wickersley","S66 2TH","24,000"]] |
4 | |
5 | for x in range(len(array)): |
6 |     f = open(str(array[x][0]) + ".txt","w") |
7 |     f.write(array[x][1] + "\n") |
8 |     f.write("\n") |
9 |     address = array[x][2].split(",") |
10 |     for y in range(len(address)): |
11 |         f.write(address[y].strip() + "\n") |
12 |     f.write(array[x][3] + "\n") |
13 |     f.write("\n") |
14 |     f.write("Salary: £" + array[x][4]) |
15 |     f.close() |
16 |      |
[15321,"Lynne Sherwood","44 Angel Way, North Cornelly","CF33 4PB","43,000"], |
line = line[:len(line)-1] #remove the last comma |
f.write(line + "\n") |
array = [ |
line = "" |
if "," in str(array[x][y]): |
[42231,"Isadore Barbra","329 Bawtry Road, Wickersley","S66 2TH","24,000"]] |
else: |
for x in range(len(array)): |
f.close() |
for y in range(len(array[x])): |
line = line + "'" + array[x][y] + "'" + "," |
line = line + str(array[x][y]) + "," |
f = open("data.csv","w") |
    [15321,"Lynne Sherwood","44 Angel Way, North Cornelly","CF33 4PB","43,000"], |
    line = line[:len(line)-1] #remove the last comma |
    f.write(line + "\n") |
array = [ |
    line = "" |
        if "," in str(array[x][y]): |
    [42231,"Isadore Barbra","329 Bawtry Road, Wickersley","S66 2TH","24,000"]] |
        else: |
for x in range(len(array)): |
f.close() |
    for y in range(len(array[x])): |
            line = line + "'" + array[x][y] + "'" + "," |
            line = line + str(array[x][y]) + "," |
f = open("data.csv","w") |
1 | array = [ |
2 |     [15321,"Lynne Sherwood","44 Angel Way, North Cornelly","CF33 4PB","43,000"], |
3 |     [42231,"Isadore Barbra","329 Bawtry Road, Wickersley","S66 2TH","24,000"]] |
4 | |
5 | f = open("data.csv","w") |
6 | for x in range(len(array)): |
7 |     line = "" |
8 |     for y in range(len(array[x])): |
9 |         if "," in str(array[x][y]): |
10 |             line = line + "'" + array[x][y] + "'" + "," |
11 |         else: |
12 |             line = line + str(array[x][y]) + "," |
13 |     line = line[:len(line)-1] #remove the last comma |
14 |     f.write(line + "\n") |
15 | f.close() |
write2DArrayToFile("maze",dest) |
y = 8 |
return dest |
dest[x][y] = "." |
mini.append(" ") |
dest.append(mini) |
for x in range(len(arr)): |
if arr[a] == "S": |
f.write(arr[x][y]) |
f.write("\n") |
f.close() |
f = open(name + ".txt","w") |
x = 8 |
dest = [] |
dest = blank2DArray(17) |
x = x + 1 |
dest[8][8] = "." |
for y in range(len(arr[x])): |
def write2DArrayToFile(name,arr): |
for x in range(17): |
y = y - 1 |
def plotRoute(arr): |
x = x - 1 |
mini = [] |
if x >= 0 and x <= 16 and y >= 0 and y <= 16: |
dest[x][y] = "X" |
if arr[a] == "E": |
def blank2DArray(num): |
if arr[a] == "W": |
for y in range(17): |
y = y + 1 |
plotRoute(["N","W","W","S","S","S","E","E","E","N","N","E","N","E","N"]) |
for a in range(len(arr)): |
if arr[a] == "N": |
    write2DArrayToFile("maze",dest) |
    y = 8 |
    return dest |
            dest[x][y] = "." |
            mini.append(" ") |
        dest.append(mini) |
    for x in range(len(arr)): |
        if arr[a] == "S": |
            f.write(arr[x][y]) |
        f.write("\n") |
    f.close() |
    f = open(name + ".txt","w") |
    x = 8 |
    dest = [] |
    dest = blank2DArray(17) |
            x = x + 1 |
    dest[8][8] = "." |
        for y in range(len(arr[x])): |
def write2DArrayToFile(name,arr): |
    for x in range(17): |
            y = y - 1 |
def plotRoute(arr): |
            x = x - 1 |
        mini = [] |
        if x >= 0 and x <= 16 and y >= 0 and y <= 16: |
    dest[x][y] = "X" |
        if arr[a] == "E": |
def blank2DArray(num): |
        if arr[a] == "W": |
        for y in range(17): |
            y = y + 1 |
plotRoute(["N","W","W","S","S","S","E","E","E","N","N","E","N","E","N"]) |
    for a in range(len(arr)): |
        if arr[a] == "N": |
1 | def write2DArrayToFile(name,arr): |
2 |     f = open(name + ".txt","w") |
3 |     for x in range(len(arr)): |
4 |         for y in range(len(arr[x])): |
5 |             f.write(arr[x][y]) |
6 |         f.write("\n") |
7 |     f.close() |
8 |      |
9 | def blank2DArray(num): |
10 |     dest = [] |
11 |     for x in range(17): |
12 |         mini = [] |
13 |         for y in range(17): |
14 |             mini.append(" ") |
15 |         dest.append(mini) |
16 |     return dest |
17 | |
18 | def plotRoute(arr): |
19 |     dest = blank2DArray(17) |
20 |     dest[8][8] = "." |
21 |     x = 8 |
22 |     y = 8 |
23 |     for a in range(len(arr)): |
24 |         if arr[a] == "N": |
25 |             x = x - 1 |
26 |         if arr[a] == "S": |
27 |             x = x + 1 |
28 |         if arr[a] == "W": |
29 |             y = y - 1 |
30 |         if arr[a] == "E": |
31 |             y = y + 1 |
32 |         if x >= 0 and x <= 16 and y >= 0 and y <= 16: |
33 |             dest[x][y] = "." |
34 |     dest[x][y] = "X" |
35 |     write2DArrayToFile("maze",dest) |
36 |      |
37 | plotRoute(["N","W","W","S","S","S","E","E","E","N","N","E","N","E","N"]) |
f.write("-" * (num * 6 - 2) + "\n") |
f.write(" | ") |
else: |
elif y == 0: |
f = open("multiply.txt","w") |
f.write(str(x).ljust(4) + "| ") |
f.write(str(y).ljust(3) + "| ") |
def createMultiplicationTable(num): |
num = num + 1 |
f.write(str(x*y).ljust(4) + "| ") |
for x in range(num): |
elif x == 0: |
createMultiplicationTable(10) |
f.close() |
for y in range(num): |
if x == 0 and y == 0: |
f.write("\n") |
        f.write("-" * (num * 6 - 2) + "\n") |
                f.write(" | ") |
            else: |
            elif y == 0: |
    f = open("multiply.txt","w") |
                f.write(str(x).ljust(4) + "| ") |
                f.write(str(y).ljust(3) + "| ") |
def createMultiplicationTable(num): |
    num = num + 1 |
                f.write(str(x*y).ljust(4) + "| ") |
        for x in range(num): |
            elif x == 0: |
createMultiplicationTable(10) |
    f.close() |
    for y in range(num): |
            if x == 0 and y == 0: |
        f.write("\n") |
1 | def createMultiplicationTable(num): |
2 |     num = num + 1 |
3 |     f = open("multiply.txt","w") |
4 |     for y in range(num): |
5 |         for x in range(num): |
6 |             if x == 0 and y == 0: |
7 |                 f.write(" | ") |
8 |             elif y == 0: |
9 |                 f.write(str(x).ljust(4) + "| ") |
10 |             elif x == 0: |
11 |                 f.write(str(y).ljust(3) + "| ") |
12 |             else: |
13 |                 f.write(str(x*y).ljust(4) + "| ") |
14 |         f.write("\n") |
15 |         f.write("-" * (num * 6 - 2) + "\n") |
16 |     f.close() |
17 |              |
18 | createMultiplicationTable(10) |
19 |              |